package dog.gui.calendar;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import containers.Appointment;
import dog.model.Model;

public class AppointmentRenderer implements Comparable<AppointmentRenderer>
	{
	Appointment app;
	Color color;
	Day day;
	int x;
	int y;
	int width;
	int height;
	int depth;
	double startTime,endTime;
	Model model;
    public void manualPaint(Graphics g)
    	{
    	//Draw a colored rectangle
    	int status=mouseStatus();
    	if (status==2)
    		g.setColor(Color.BLUE);
    	else if (status==1)
    		g.setColor(color.brighter());
    	else
    		g.setColor(color);
        g.fillRect(x,y,width,height);
        //Draw an outline
        g.setColor(new Color(0,0,0,64));
        g.drawRect(x,y,width,height);
        //Draw some text
        int textHeight = Math.min(12, height);
        g.setFont(new Font("Courier New", 0, textHeight));
        if (status==2)
        	g.setColor(Color.WHITE);
        else
        	g.setColor(Color.BLACK);
//        g.drawString(""+app.ownerPersonID+", "+app.appointmentID, x+2, y+textHeight);
        g.drawString("" + app.subject, x+2, y+textHeight);// + "\n" + app.startTime + " - " + app.endTime + "\n" + (app.locationName.equals("") ? model.getRoom(app.roomID) : app.locationName)
        }
    public int mouseStatus()
    	{
    	return day.calendarPanel.getStatus(app.getKey());
    	//Returns 2 if this is selected, 1 if the mouse hovers over it, 0 otherwise.
    	}
    public Appointment getAppointment()
    	{
    	return app;
    	}
    public AppointmentRenderer(Appointment appointment,Model model,Day day)
    	{
    	this.model = model;
    	app=appointment;
    	color=new Color(Color.HSBtoRGB(((float)model.exactHourOfDay(app.startTime)/24+(float)model.exactHourOfDay(app.endTime)/24)%1,0.5f,1.0f));
    	this.day=day;
    	x=0;
    	y=0;
    	width=96;
    	height=16;
    	if(app.startTime.after(model.getStartOfDay(day.weekDay)) && app.startTime.before(model.getEndOfDay(day.weekDay)))
    		startTime=model.exactHourOfDay(app.startTime);
    	else
    		startTime=0;
    	if(app.endTime.after(model.getStartOfDay(day.weekDay)) && app.endTime.before(model.getEndOfDay(day.weekDay)))
    		endTime = model.exactHourOfDay(app.endTime);
    	else
    		endTime = 24;
    	}
	@Override
	public int compareTo(AppointmentRenderer girl)
		{
		return this.getAppointment().startTime.compareTo(girl.getAppointment().startTime);
		}

	}
